﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using App1AppHandler;
using Reborn_WorldServer;
using Reborn_WorldServer.App1AppHandler;

namespace Reborn_Server.App1AppHandler
{
    public class Potion_PermStat20 : IConsumable
    {
        public bool MeetsConsumeRequirements(Character myCharacter, Loot lootitem)
        {
            bool meetsRequirements = false;
            string statToUse = "";
            if (lootitem.Name.Contains("Strength") && myCharacter.Strength < 25)
            {
                meetsRequirements = true;
                statToUse = "Strength";
            }
            if (lootitem.Name.Contains("Intelligence") && myCharacter.Intelligence < 25)
            {
                meetsRequirements = true;
                statToUse = "Intelligence";
            }
            if (lootitem.Name.Contains("Wisdom") && myCharacter.Wisdom < 25)
            {
                meetsRequirements = true;
                statToUse = "Wisdom";
            }
            if (lootitem.Name.Contains("Agility") && myCharacter.Agility < 25)
            {
                meetsRequirements = true;
                statToUse = "Agility";
            }
            if (lootitem.Name.Contains("Dexterity") && myCharacter.Dexterity < 25)
            {
                meetsRequirements = true;
                statToUse = "Dexterity";
            }

            if (meetsRequirements == false)
            {
                myCharacter.PlaySound("Ding", myCharacter.MapX, myCharacter.MapY);
                myCharacter.SendMessage("Your " + statToUse + " is to high for this potion", "server");
            }

            return meetsRequirements;
        }

        public void Consume(Character myCharacter, Loot lootitem)
        {
            LockItem lockItem = Managers.GameHandler.GetLockItem(myCharacter.MapID, myCharacter.Instance);
            lock (lockItem.LockObj)
            {
                Map CurrentMap = Managers.GameHandler.GetMap(myCharacter.MapID, myCharacter.Instance);

                //List<Character> CharactersWithin4 = new List<Character>();
                foreach (MapItem mapitem in CurrentMap.MapItems)
                {
                    if (Math.Abs(mapitem.MapX - myCharacter.MapX) <= 8 && Math.Abs(mapitem.MapY - myCharacter.MapY) <= 8)
                    {
                        foreach (CreatureBase creaturebase in mapitem.CreaturesBases)
                        {
                            if (creaturebase is Character)
                            {
                                Character character = (Character)creaturebase;
                                character.PlaySound("DrinkBottle", myCharacter.MapX, myCharacter.MapY);
                            }
                        }
                    }
                    //if (Math.Abs(mapitem.MapX - myCharacter.MapX) <= 4 && Math.Abs(mapitem.MapY - myCharacter.MapY) <= 4)
                    //{
                    //    foreach (CreatureBase creaturebase in mapitem.CreaturesBases)
                    //    {
                    //        if (creaturebase is Character)
                    //            CharactersWithin4.Add((Character)creaturebase);
                    //    }
                    //}
                }

                bool updateCharacter = false;
                if (lootitem.Name.Contains("Strength") && myCharacter.Strength < 25)
                {
                    myCharacter.Strength = myCharacter.Strength + 1;
                    updateCharacter = true;
                }
                if (lootitem.Name.Contains("Intelligence") && myCharacter.Intelligence < 25)
                {
                    myCharacter.Intelligence = myCharacter.Intelligence + 1;
                    updateCharacter = true;
                }
                if (lootitem.Name.Contains("Wisdom") && myCharacter.Wisdom < 25)
                {
                    myCharacter.Wisdom = myCharacter.Wisdom + 1;
                    updateCharacter = true;
                }
                if (lootitem.Name.Contains("Agility") && myCharacter.Agility < 25)
                {
                    myCharacter.Agility = myCharacter.Agility + 1;
                    updateCharacter = true;
                }
                if (lootitem.Name.Contains("Dexterity") && myCharacter.Dexterity < 25)
                {
                    myCharacter.Dexterity = myCharacter.Dexterity + 1;
                    updateCharacter = true;
                }
                if (updateCharacter == true)
                    myCharacter.Update_Character();
            }
        }
    }
}
